package com.xinzhi.savingpot.userinfo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xinzhi.savingpot.userinfo.entity.UserInfo;
import com.xinzhi.savingpot.userinfo.mapper.IPersonalCenter;
import com.xinzhi.savingpot.userinfo.service.IPersonalCenterService;
import com.xinzhi.savingpot.util.BaseResponse;
import com.xinzhi.savingpot.vo.PersonalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PersonalCenterServiceImpl implements IPersonalCenterService {
    @Autowired
    private IPersonalCenter iPersonalCenter;
    @Override
    public String searchResult(String userId) {
        if(userId!=null){
            Integer user = Integer.valueOf(userId);
            System.out.println(user);
            UserInfo userInfo = iPersonalCenter.searchResult(user);

            return JSONObject.toJSONString(new BaseResponse(200,"成功放回信息",userInfo));
        }else {
            return JSONObject.toJSONString(new BaseResponse(400,"失败"));
        }
    }

    @Override
    public BaseResponse updatePersonal(PersonalVo personalVo) {
        if (personalVo.getUserId() != null) {
            long user = Long.valueOf(personalVo.getUserId());
            UserInfo us = new UserInfo();
            us.setUserNickName(personalVo.getUserNickName());
            us.setUserHeadPhoto(personalVo.getUserHeadPhoto());
            us.setPhone(personalVo.getPhone());
            us.setUserId(Integer.valueOf(personalVo.getUserId()));

            int uss = iPersonalCenter.updatePersonal(us);
//        }
//        if(personalVo.getPhone()!=null){
//            String personal = personalVo.getPhone();
//        }
//        if(personalVo.getUserHeadPhoto()!=null){}
            return new BaseResponse(1, "修改成功", uss);
        } else {
                return new BaseResponse(400,"失败没有确定的用户");
        }
    }
}
